<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Customer </title>
    </head>
    <body>
        <div class="container">
            
            <c:if test="${null == model}">
                <img src="<c:url value="/resources/pictures/error.png" />" title="<fmt:message key="customer.notfound" />" />
                <b><fmt:message key="customer.notfound" /></b>
            </c:if>
            <c:if test="${null != model}">
                <c:if test="${null == model.customer}">
                    <img src="<c:url value="/resources/pictures/error.png" />" title="<fmt:message key="customer.notfound" />" />
                    <b><fmt:message key="customer.notfound" /></b>
                </c:if>

                <c:if test="${null != model.customer}">
                    <button onclick="location.href = '<c:url value="/customer/index"/>'" class="btn btn-default"><fmt:message key="back" /></button><h1><fmt:message key="customer" /> <c:out value="${model.customer.firstName}"/> <c:out value="${model.customer.lastName}"/></h1>
                    <sec:authorize access="hasRole('ROLE_ADMIN')">
                        <div>
                            <a href="<c:url value="/customer/remove/${model.customer.id}"/>" onclick="return confirm('<fmt:message key="remove.confirm" />')">
                                <img src="<c:url value="/resources/pictures/remove.png" />" title="<fmt:message key="remove" />" /> <fmt:message key="remove" />
                            </a>
                        </div>
                    </sec:authorize>
                    <table class="table table-striped">
                        <tr>
                            <td><b><fmt:message key="customer.firstname" /></b></td>
                            <td><c:out value="${model.customer.firstName}"/></td>
                        </tr>
                        <tr>
                            <td><b><fmt:message key="customer.lastname" /></b></td>
                            <td><c:out value="${model.customer.lastName}"/></td>
                        </tr>
                        <tr>
                            <td><b><fmt:message key="customer.email" /></b></td>
                            <td><c:out value="${model.customer.email}"/></td>
                        </tr>
                        <tr>
                            <td><b><fmt:message key="customer.phone" /></b></td>
                            <td><c:out value="${model.customer.phone}"/></td>
                        </tr>
                        <tr>
                            <td><b><fmt:message key="customer.address" /></b></td>
                            <td>
                                <div>
                                    <c:out value="${model.customer.street}"/>
                                </div>
                                <div>
                                    <c:out value="${model.customer.zipCode}"/> <c:out value="${model.customer.city}"/>
                                </div>
                                <div>
                                    <c:out value="${model.customer.country}"/>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td><b><fmt:message key="customer.type" /></b></td>
                            <td><c:out value="${model.customer.customerType}"/></td>
                        </tr>
                        <tr>
                            <td><b><fmt:message key="customer.vat" /></b></td>
                            <td><c:out value="${model.customer.vatNumber}"/></td>
                        </tr>
                        <tr>
                            <td><b><fmt:message key="customer.companynumber" /></b></td>
                            <td><c:out value="${model.customer.companyNumber}"/></td>
                        </tr>
                    </table>
                </c:if>
            </c:if>
        </div>

        <c:if test="${null != model.customer}">
            <div class="container">
                <div>
                    <h3><fmt:message key="rentals" /></h3>
                </div>

                <c:if test="${empty model.rentals}">
                    <fmt:message key="rental.notrentalsavailable" />
                </c:if>
                <c:if test="${not empty model.rentals}">

                    <table class="table table-striped">
                        <th>
                            <fmt:message key="detail" />
                        </th>
                        <th>
                            <fmt:message key="machine" />
                        </th>
                        <th>
                            <fmt:message key="rental.dateOfRent" />
                        </th>
                        <th>
                            <fmt:message key="rental.duration" />
                        </th>
                        <th>
                            <fmt:message key="rental.dateOfReturn" />
                        </th>
                        <th>
                            <fmt:message key="edit" />
                        </th>
                        <c:forEach var="r" items="${model.rentals}">
                            <tr>
                                <td>
                                    <a href="<c:url value="/rental/detail/${r.id}"/>">
                                        <img src="<c:url value="/resources/pictures/detail.png" />" title="<fmt:message key="detail" />" /> <fmt:message key="detail" />
                                    </a>
                                </td>
                                <td>
                                    <a href="<c:url value="/machine/detail/${r.machine.id}"/>"><c:out value="${r.machine.code}"/> <c:out value="${r.machine.brand}"/> <c:out value="${r.machine.model}"/></a>
                                </td>
                                <td>
                                    <c:out value="${r.dateOfRent}"/>
                                </td>
                                <td>
                                    <c:out value="${r.duration}"/>
                                </td>
                                <td>
                                    <c:out value="${r.dateOfReturn}"/>
                                </td>
                                <td>
                                    <a href="<c:url value="/rental/edit/${r.id}"/>">
                                        <img src="<c:url value="/resources/pictures/edit.png" />" title="<fmt:message key="edit" />" /> <fmt:message key="edit" />
                                    </a>
                                </td>
                            </tr>
                        </c:forEach>
                    </table>
                </c:if>   
            </div>            
        </c:if>
    </body>
</html>
